﻿// This code is released under the BSD license.
namespace PugLib.UnitTest
{
    #region

    using Functional;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    #endregion

    /// <summary>
    ///This is a test class for MonadsTest and is intended
    ///to contain all MonadsTest Unit Tests
    ///</summary>
    [TestClass]
    public class MonadsTest
    {
        [TestMethod]
        public void TestMonads()
        {
            Identity<int> t = 5.ToIdentity().SelectMany(x => 6.ToIdentity(), (x, y) => x + y);
            Assert.AreEqual(11, t.Value);

            Maybe<int> r = from x in 5.ToMaybe()
                           from y in Maybe<int>.Nothing
                           select x + y;
            Assert.AreEqual(r.Value, 5);

            Identity<int> s = from x in 5.ToIdentity()
                              from y in 6.ToIdentity()
                              select x + y;
            Assert.AreEqual(s.Value, 11);

            K<int, string> w = from x in 7.ToContinuation<int, string>()
                               from y in 6.ToContinuation<int, string>()
                               select x + y;

            string result = w(z => z.ToString().Replace('1', 'a'));
            Assert.AreEqual(result, "a3");
        }
    }
}